package com.power.using.askapp.base;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

import com.power.using.askapp.R;
import com.power.using.askapp.interfaces.DialogClick;
import com.power.using.askapp.utils.ToastUtils;
import com.power.using.askapp.utils.loading.IosAlertDialog;

import me.yokeyword.fragmentation.SupportFragment;

/*
*
* 四个主Fragment 继承的 base
* */
public class BaseMainFragment extends SupportFragment {

    // 再点一次退出程序时间设置
    private static final long WAIT_TIME = 2000L;
    private long TOUCH_TIME = 0;


    /**
     * 处理回退事件
     *
     * @return
     */
    @Override
    public boolean onBackPressedSupport() {
        if (System.currentTimeMillis() - TOUCH_TIME < WAIT_TIME) {
            _mActivity.finish();
        } else {
            TOUCH_TIME = System.currentTimeMillis();
            Toast.makeText(_mActivity, R.string.press_again_exit, Toast.LENGTH_SHORT).show();
        }

        return true;
    }

    protected void showAlertDialogNoMsg(Context context, String titleContent, String message, final DialogClick dialogClick) {

        new IosAlertDialog(context).builder().setTitle(titleContent)
                .setPositiveButton("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialogClick.PositiveMessage();
                    }
                }).setNegativeButton("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogClick.NegativeMessage();
            }
        }).show();
    }


    //Toast显示
    protected void showShortToast(Context context, String string) {
        ToastUtils.showShortToast(context, string);
    }


}
